#include <ros/ros.h>
#include <rviz_button/add_rvizBtn.h>

namespace rviz_button_plugin{
    AddRvizBtn::AddRvizBtn(QWidget* parent): rviz::Panel(parent){
        auto *button_layout = new QHBoxLayout;
        btn1_ = new QPushButton(tr("测试按钮1"),this);
        button_layout->addWidget(btn1_);
        btn2_ = new QPushButton(tr("测试按钮2"),this);
        button_layout->addWidget(btn2_);

        setLayout(button_layout);

        connect(btn1_,&QPushButton::clicked,this,&AddRvizBtn::add_btn1);
        connect(btn2_,&QPushButton::clicked,this,&AddRvizBtn::add_btn2);

        btn_pub1_ = nh_.advertise<std_msgs::String>("add_btn1",10);
        btn_pub2_ = nh_.advertise<std_msgs::String>("add_btn2",10);

    }
    void AddRvizBtn::add_btn1(){
        std_msgs::String msg;
        msg.data = "test1";
        ROS_INFO("测试消息发布！");
        btn_pub1_.publish(msg);
    }
    void AddRvizBtn::add_btn2(){
        std_msgs::String msg;
        msg.data = "test2";
        ROS_INFO("测试消息发布！");
        btn_pub2_.publish(msg);
    }
    void AddRvizBtn::save(rviz::Config config) const{
        rviz::Panel::save(config);
    }
    void AddRvizBtn::load(const rviz::Config& config){
        rviz::Panel::load(config);  
    }
}
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(rviz_button_plugin::AddRvizBtn,rviz::Panel)